
# week.information
  if ("AGE" %in% option[[i]]){
    select.information <- c(group.begin[j], group.avg[j], group.end[j], length(cases.in.model[,1]))
  } else {select.information <- c(week.begin[j], week[j], week.end[j], length(cases.in.model[,1]))}

# dfd.avg
dfd.avg <- mean(cases.in.model$dfdgg10.a)

# sample.age.attributes 
ego.age.avg <- mean(cases.in.model$age.gg10.e)
ego.age.lowquart <- unname(summary(cases.in.model$age.gg10.e))[2]
ego.age.median <- unname(summary(cases.in.model$age.gg10.e))[3]
ego.age.highquart <- unname(summary(cases.in.model$age.gg10.e))[5]
alter.age.avg <- mean(cases.in.model$age.gg10.a)
alter.age.lowquart <- unname(summary(cases.in.model$age.gg10.a))[2]
alter.age.median <- unname(summary(cases.in.model$age.gg10.a))[3]
alter.age.highquart <- unname(summary(cases.in.model$age.gg10.a))[5]
age.at.death <- mean(cases.in.model$ageatdeath.a)
ea.agediscrep.avg <- mean(cases.in.model$ea.agediscrep)
ea.agediscrep.median <- median(cases.in.model$ea.agediscrep)

sample.age.attributes <- c(ego.age.avg, ego.age.lowquart, ego.age.median, ego.age.highquart, alter.age.avg, alter.age.lowquart, alter.age.median, alter.age.highquart, age.at.death, ea.agediscrep.avg, ea.agediscrep.median)

# sample.occupancy.attributes 
hid.occnum.avg <- mean(cases.in.model$hid.occnum)
hid.occnum.median <- median(cases.in.model$hid.occnum)

sample.occupancy.attributes <- c(hid.occnum.avg, hid.occnum.median)

# sample.turnout.attributes 
turnout.gg10 <- mean(cases.in.model$gg10.e)
turnout.gp10 <- mean(cases.in.model$gp10.e)
turnout.ss9 <- mean(cases.in.model$ss9.e)
turnout.pg8 <- mean(cases.in.model$pg8.e)
turnout.pp8 <- mean(cases.in.model$pp8.e)
turnout.gg6 <- mean(cases.in.model$gg6.e)
turnout.gp6 <- mean(cases.in.model$gp6.e)
turnout.ss5 <- mean(cases.in.model$ss5.e)
turnout.pg4 <- mean(cases.in.model$pg4.e)

turnout.pg8.alter <- mean(cases.in.model$pg8.a)
turnout.gg6.alter <- mean(cases.in.model$gg6.a)
turnout.gp6.alter <- mean(cases.in.model$gp6.a)
turnout.ss5.alter <- mean(cases.in.model$ss5.a)
turnout.pg4.alter <- mean(cases.in.model$pg4.a)

sample.turnout.attributes <- c(turnout.gg10, turnout.gp10, turnout.ss9, turnout.pg8, turnout.pp8, turnout.gg6, turnout.gp6, turnout.ss5, turnout.pg4, turnout.pg8.alter, turnout.gg6.alter, turnout.gp6.alter, turnout.ss5.alter, turnout.pg4.alter)

# sample.gender.attributes 
female.to.male <- table(cases.in.model$female.e)[2]/table(cases.in.model$male.e)[2]
female.ego.age.avg <- mean(cases.in.model[cases.in.model$female.e==1,]$age.gg10.e)
female.ego.age.median <- median(cases.in.model[cases.in.model$female.e==1,]$age.gg10.e)
female.alter.avg <- mean(cases.in.model[cases.in.model$female.a==1,]$age.gg10.a)
female.alter.age.median <- median(cases.in.model[cases.in.model$female.a==1,]$age.gg10.a)
female.egos <- length(cases.in.model[cases.in.model$female.e==1,]$age.gg10.e)
female.alters <- length(cases.in.model[cases.in.model$female.a==1,]$age.gg10.a)
male.ego.age.avg <- mean(cases.in.model[cases.in.model$male.e==1,]$age.gg10.e)
male.ego.age.median <- median(cases.in.model[cases.in.model$male.e==1,]$age.gg10.e)
male.alter.age.avg <- mean(cases.in.model[cases.in.model$male.a==1,]$age.gg10.a)
male.alter.age.median <- median(cases.in.model[cases.in.model$male.a==1,]$age.gg10.a)
male.egos <- length(cases.in.model[cases.in.model$male.e==1,]$age.gg10.e)
male.alters <- length(cases.in.model[cases.in.model$male.a==1,]$age.gg10.a)

sample.gender.attributes <- c(female.to.male, female.ego.age.avg, female.ego.age.median, female.alter.avg, female.alter.age.median, female.egos, female.alters,  male.ego.age.avg, male.ego.age.median, male.alter.age.avg, male.alter.age.median, male.egos, male.alters)

# sample.party.attributes 
ego.dem.to.rep <- table(cases.in.model$dem.e)[2]/table(cases.in.model$rep.e)[2]
alter.dem.to.rep <- table(cases.in.model$dem.a)[2]/table(cases.in.model$rep.a)[2]
dem.egos <- mean(cases.in.model$dem.e)
dem.alters <- mean(cases.in.model$dem.a)
rep.egos <- mean(cases.in.model$rep.e)
rep.alters <- mean(cases.in.model$rep.a)

sample.party.attributes <- c(ego.dem.to.rep, alter.dem.to.rep, dem.egos, dem.alters, rep.egos, rep.alters)

# sample.voting.attributes 
same.proportion <- length(cases.in.model[cases.in.model$gg6.e==cases.in.model$gg6.a&cases.in.model$gp6.e==cases.in.model$gp6.a& cases.in.model$ss5.e==cases.in.model$ss5.a&cases.in.model$pg4.e==cases.in.model$pg4.a,]$gg10.e)/length(cases.in.model$gg10.e)

same.count <- length(cases.in.model[cases.in.model$gg6.e==cases.in.model$gg6.a&cases.in.model$gp6.e==cases.in.model$gp6.a& cases.in.model$ss5.e==cases.in.model$ss5.a&cases.in.model$pg4.e==cases.in.model$pg4.a,]$gg10.e)

more.proportion <- length(cases.in.model[(cases.in.model$gg6.e+cases.in.model$gp6.e+cases.in.model$ss5.e+cases.in.model$pg4.e)>(cases.in.model$gg6.a+cases.in.model$gp6.a+cases.in.model$ss5.a+cases.in.model$pg4.a),]$gg10.e)/length(cases.in.model$gg10.e)

more.count <- length(cases.in.model[(cases.in.model$gg6.e+cases.in.model$gp6.e+cases.in.model$ss5.e+cases.in.model$pg4.e)>(cases.in.model$gg6.a+cases.in.model$gp6.a+cases.in.model$ss5.a+cases.in.model$pg4.a),]$gg10.e)

fewer.proportion <- length(cases.in.model[(cases.in.model$gg6.e+cases.in.model$gp6.e+cases.in.model$ss5.e+cases.in.model$pg4.e)<(cases.in.model$gg6.a+cases.in.model$gp6.a+cases.in.model$ss5.a+cases.in.model$pg4.a),]$gg10.e)/length(cases.in.model$gg10.e)

fewer.count <- length(cases.in.model[(cases.in.model$gg6.e+cases.in.model$gp6.e+cases.in.model$ss5.e+cases.in.model$pg4.e)<(cases.in.model$gg6.a+cases.in.model$gp6.a+cases.in.model$ss5.a+cases.in.model$pg4.a),]$gg10.e)

onevote.pg4throughgg6 <- length(cases.in.model[cases.in.model$pg4.e + cases.in.model$ss5.e + cases.in.model$gp6.e + cases.in.model$gg6.e==1,]$gg10.e)/length(cases.in.model$gg10.e)

twovotes.pg4throughgg6 <- length(cases.in.model[cases.in.model$pg4.e + cases.in.model$ss5.e + cases.in.model$gp6.e + cases.in.model$gg6.e==2,]$gg10.e)/length(cases.in.model$gg10.e)

threevotes.pg4throughgg6 <- length(cases.in.model[cases.in.model$pg4.e + cases.in.model$ss5.e + cases.in.model$gp6.e + cases.in.model$gg6.e==3,]$gg10.e)/length(cases.in.model$gg10.e)

fourvotes.pg4throughgg6 <- length(cases.in.model[cases.in.model$pg4.e + cases.in.model$ss5.e + cases.in.model$gp6.e + cases.in.model$gg6.e==4,]$gg10.e)/length(cases.in.model$gg10.e)

novotes.pg4throughgg6 <- length(cases.in.model[cases.in.model$pg4.e + cases.in.model$ss5.e + cases.in.model$gp6.e + cases.in.model$gg6.e==0,]$gg10.e)/length(cases.in.model$gg10.e)

sample.voting.attributes <- c(same.proportion, same.count, more.proportion,more.count, fewer.proportion,fewer.count, onevote.pg4throughgg6, twovotes.pg4throughgg6, threevotes.pg4throughgg6, fourvotes.pg4throughgg6, novotes.pg4throughgg6)

## conditional attributes

if ("pop.density" %in% names(casecontrol) & "percapita.income" %in% names(casecontrol)){
# sample.popdensity.attributes 
pop.density.avg <- mean(cases.in.model$pop.density)
pop.density.median <- median(cases.in.model$pop.density)

sample.popdensity.attributes <- c(pop.density.avg, pop.density.median)

# sample.percapitaincome.attributes 
percapita.income.avg <- mean(cases.in.model$percapita.income)
percapita.income.median <- median(cases.in.model$percapita.income)

sample.percapitaincome.attributes <- c(percapita.income.avg, percapita.income.median)
}

if ("regdate.e" %in% names(casecontrol) & "regdate.a" %in% names(casecontrol)){
# sample.regdate.attributes 
ego.regdate <- median(cases.in.model$regdate.e)
alter.regdate <- median(cases.in.model$regdate.a)

sample.regdate.attributes <- c(ego.regdate, alter.regdate)
}

cases.in.model.stats <- c(select.information, dfd.avg, sample.age.attributes, sample.occupancy.attributes, sample.turnout.attributes, sample.gender.attributes, sample.party.attributes, sample.voting.attributes)

if ("pop.density" %in% names(casecontrol) & "percapita.income" %in% names(casecontrol)){
  cases.in.model.stats <- c(cases.in.model.stats, sample.popdensity.attributes, sample.percapitaincome.attributes)
}

if ("regdate.e" %in% names(casecontrol) & "regdate.a" %in% names(casecontrol)){
  cases.in.model.stats <- c(cases.in.model.stats, sample.regdate.attributes)
}
